JObj.UI = {};
(function($,$$){
	
	$.JPos = {};
	(function($){
	
		$.getAbsPos = function(pTarget){
			pTarget = JObj.$(pTarget);
			
			if(!pTarget.getBoundingClientRect){
				var x_ = y_ = 0;

                while(pTarget.offsetParent){
                        x_ += pTarget.offsetLeft;
                        y_ += pTarget.offsetTop;
                        pTarget = pTarget.offsetParent;
                }
				x_ += pTarget.offsetLeft;
				y_ += pTarget.offsetTop;
				return {x:x_,y:y_}
			}else{
				var body = document.compatMode == 'CSS1Compat' ? document.documentElement : document.body;
				var rect = pTarget.getBoundingClientRect()
				return {x:rect.left + body.scrollLeft,y:rect.top + body.scrollTop};
			}
		}
		
		$.getRelativePos = function(pTarget,pRelative){
			var org = pTarget = JObj.$(pTarget);
			pRelative = JObj.$(pRelative);

            var x_ = y_ = 0;
            var hr = false;//relative 是否是 target 的某个祖先 offsetParent

            while(pTarget.offsetParent){
                    if(pTarget.offsetParent == pRelative){
                        hr = true;
                        break;
                    }
                    x_ += pTarget.offsetLeft;
                    y_ += pTarget.offsetTop;
                    pTarget = pTarget.offsetParent;
            }

            if(!hr && pRelative.getBoundingClientRect)
                return $.getAbsPos(org)
            else
                return {x:x_,y:y_};
		}
		
		$.getEventPos = function(evt){
				var _x,_y;
				evt = JObj.getEvent(evt);
				if(evt.pageX || evt.pageY){
					_x = evt.pageX;
					_y = evt.pageY;
				}else if(evt.clientX || evt.clientY){
					_x = evt.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft) - (document.body.clientLeft || document.documentElement.clientLeft);
					_y = evt.clientY + (document.body.scrollTop || document.documentElement.scrollTop) - (document.body.clientTop || document.documentElement.clientTop);
				}else{
					return $.getAbsPos(evt.target);
				}
				return {x:_x,y:_y};
		}
	
		$.moveToScreenCenter = function(obj){
			obj = JObj.$(obj);
			var body = document.compatMode == 'CSS1Compat' ? document.documentElement : document.body;
			var s1 = {w:body.clientWidth,h:body.clientHeight};
			var s2 = {w:obj.clientWidth,h:obj.clientHeight};
			
			var t = (s1.h - s2.h) / 2 + body.scrollTop;
			var l = (s1.w - s2.w) / 2 + body.scrollLeft;
			
			JObj.css(obj,{left:l,top:t,position:'absolute'});
		}
	})($.JPos);


    $.JLayerManager = {};
    (function($){

        if(JObj.Browser.opera || JObj.Browser.safari){
            $.MAX_ZINDEX = 16777299;//16777299  1
            $.ZINDEX_STEP = 1;
        }else{
            $.MAX_ZINDEX = 2147483647;
            $.ZINDEX_STEP = 1;
        }

    })($.JLayerManager);
	
})(JObj.UI,JObj);